<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link type="text/css" rel="stylesheet" href="../source/css/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="../source/css/bootstrap-responsive.css" />
<link type="text/css" rel="stylesheet" href="../source/css/docs.css" />
<link type="text/css" rel="stylesheet" href="../source/css/monokai.css" />
<link type="text/css" rel="stylesheet" href="../source/css/font-awesome.css">

<script type="text/javascript" src="../source/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../source/js/bootstrap.js"></script>
<script type="text/javascript" src="../source/js/highlight.pack.js"></script>
<script type="text/x-mathjax-config"> 
    MathJax.Hub.Config({ 
        tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} 
    }); 
</script>
<script type="text/javascript"
    src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<title>vijos_list</title>

</head>
<body data-spy="scroll" data-target=".bs-docs-sidebar">
<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>

            <!-- Be sure to leave the brand out there if you want it shown -->
            <a class="brand" href="../index.html">Wahacer's blogs</a>

            <!-- Everything you want hidden at 940px or less, place within here -->
            <div class="nav-collapse collapse">
                <!-- .nav, .navbar-search, .navbar-form, etc -->
                <ul class="nav">
                    <li class="">
                        <a href="../index.html">Index</a>
                    </li>
                    
                    <li class="">
                        <a href="../Solution/index.html">Solution</a>
                    </li>
                    
                    <li class="">
                        <a href="../Algorithm/index.html">Algorithm</a>
                    </li>
                    

                </ul>
            </div>
        </div>
    </div>
</div>

<div class="container-fluid">
    <div class="row-fluid">
        <!--　侧边拦 -->
        <div class="span2 bs-docs-sidebar">
            <br><br><br>
            <div align="center"><img src="../source/picture/photo.jpg" alt="photo" width="250" height="250" /></div>
            <p align="center"><strong>Wahacer</strong></p>

        </div>

        <!-- 主内容　-->
        <div class="span8">
            <br>
            <!--Body content-->
            <h1 id="toc-0">vijos的训练计划</h1>
<h1 id="toc-1">从零开始</h1>
<h2 id="toc-2">最初的最初</h2>
<h3 id="toc-3">基础能力</h3>
<p>1、</p>
<pre><code>记数问题

描述

试计算在区间 1 到 n 的所有整数中,数字 x(0 ≤ x ≤ 9)共出现了多少次?例如,在 1 到 11 中,即在 1、2、3、4、5、6、7、8、9、10、11 中,数字 1 出现了 4 次。

格式

输入格式
输入共 1 行,包含 2 个整数 n、x,之间用一个空格隔开。

输出格式
输出共 1 行,包含一个整数,表示 x 出现的次数。

样例1

样例输入1

11 1

样例输出1

4

限制
每个测试点1s。

提示
对于 100%的数据,1≤ n ≤ 1,000,000,0 ≤ x ≤ 9。

来源
NOIP 2013 普及组</code></pre>
<p>无脑统计</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">ans</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%d%d&quot;</span><span class="p">,</span><span class="o">&amp;</span><span class="n">a</span><span class="p">,</span><span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">a</span><span class="p">;</span><span class="n">i</span><span class="o">&gt;=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">--</span><span class="p">){</span>
        <span class="kt">int</span> <span class="n">x</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
        <span class="k">while</span><span class="p">(</span><span class="n">x</span><span class="p">){</span>
            <span class="kt">int</span> <span class="n">xx</span><span class="o">=</span><span class="n">x</span><span class="o">%</span><span class="mi">10</span><span class="p">;</span>
            <span class="k">if</span><span class="p">(</span><span class="n">b</span><span class="o">==</span><span class="n">xx</span><span class="p">)</span> <span class="n">ans</span><span class="o">++</span><span class="p">;</span>
            <span class="n">x</span><span class="o">/=</span><span class="mi">10</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="n">ans</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>2、</p>
<pre><code>谁拿了最多奖学金

描述
某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种，获取的条件各自不同：
1) 院士奖学金，每人8000元，期末平均成绩高于80分（&gt;80），并且在本学期内发表1篇或1篇以上论文的学生均可获得；
2) 五四奖学金，每人4000元，期末平均成绩高于85分（&gt;85），并且班级评议成绩高于80分（&gt;80）的学生均可获得；
3) 成绩优秀奖，每人2000元，期末平均成绩高于90分（&gt;90）的学生均可获得；
4) 西部奖学金，每人1000元，期末平均成绩高于85分（&gt;85）的西部省份学生均可获得；
5) 班级贡献奖，每人850元，班级评议成绩高于80分（&gt;80）的学生干部均可获得；
只要符合条件就可以得奖，每项奖学金的获奖人数没有限制，每名学生也可以同时获得多项奖学金。例如姚林的期末平均成绩是87分，班级评议成绩82分，同时他还是一位学生干部，那么他可以同时获得五四奖学金和班级贡献奖，奖金总数是4850元。
现在给出若干学生的相关数据，请计算哪些同学获得的奖金总数最高（假设总有同学能满足获得奖学金的条件）。
格式

输入格式

输入的第一行是一个整数N（1 &lt;= N &lt;= 100），表示学生的总数。接下来的N行每行是一位学生的数据，从左向右依次是姓名，期末平均成绩，班级评议成绩，是否是学生干部，是否是西部省份学生，以及发表的论文数。姓名是由大小写英文字母组成的长度不超过20的字符串（不含空格）；期末平均成绩和班级评议成绩都是0到100之间的整数（包括0和100）；是否是学生干部和是否是西部省份学生分别用一个字符表示，Y表示是，N表示不是；发表的论文数是0到10的整数（包括0和10）。每两个相邻数据项之间用一个空格分隔。

输出格式

输出包括三行，第一行是获得最多奖金的学生的姓名，第二行是这名学生获得的奖金总数。如果有两位或两位以上的学生获得的奖金最多，输出他们之中在输入文件中出现最早的学生的姓名。第三行是这N个学生获得的奖学金的总数。

样例1

样例输入1
4
YaoLin 87 82 Y N 0
ChenRuiyi 88 78 N Y 1
LiXin 92 88 N N 0
ZhangQin 83 87 Y N 1


样例输出1
ChenRuiyi
9000
28700


限制
1s

来源
NOIp2005 第一题</code></pre>
<p>if</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;algorithm&gt;</span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">;</span>
<span class="k">struct</span> <span class="n">pp</span>
<span class="p">{</span>
    <span class="kt">char</span> <span class="n">n</span><span class="p">[</span><span class="mi">20</span><span class="p">];</span>
    <span class="kt">int</span> <span class="n">pj</span> <span class="p">,</span> <span class="n">py</span> <span class="p">;</span>
    <span class="kt">bool</span> <span class="n">sq</span> <span class="p">,</span> <span class="n">xb</span> <span class="p">,</span> <span class="n">qwq</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">lun</span> <span class="p">;</span>
    <span class="kt">int</span> <span class="n">money</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">num</span> <span class="p">;</span>   
<span class="p">}</span><span class="n">st</span><span class="p">[</span><span class="mi">101</span><span class="p">];</span>
<span class="kt">bool</span> <span class="nf">cmp</span><span class="p">(</span><span class="n">pp</span> <span class="n">a</span> <span class="p">,</span> <span class="n">pp</span> <span class="n">b</span><span class="p">){</span>
    <span class="k">if</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">money</span> <span class="o">!=</span> <span class="n">b</span><span class="p">.</span><span class="n">money</span> <span class="p">)</span> <span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">money</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">money</span> <span class="p">;</span>
    <span class="k">else</span> <span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">num</span><span class="o">&lt;</span><span class="n">b</span><span class="p">.</span><span class="n">num</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">sum</span> <span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">a</span><span class="p">;</span>
    <span class="kt">char</span> <span class="n">q</span> <span class="p">,</span> <span class="n">w</span> <span class="p">;</span>
    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span> <span class="p">;</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="n">a</span> <span class="p">;</span> <span class="n">i</span> <span class="o">++</span><span class="p">){</span>
        <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%s %d %d %c %c %d&quot;</span><span class="p">,</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">n</span><span class="p">,</span><span class="o">&amp;</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">pj</span><span class="p">,</span><span class="o">&amp;</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">py</span><span class="p">,</span><span class="o">&amp;</span><span class="n">q</span><span class="p">,</span><span class="o">&amp;</span><span class="n">w</span><span class="p">,</span><span class="o">&amp;</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">lun</span><span class="p">);</span>
        <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">num</span> <span class="o">=</span> <span class="n">i</span> <span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">q</span> <span class="o">==</span> <span class="sc">&#39;Y&#39;</span><span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">sq</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">q</span> <span class="o">==</span> <span class="sc">&#39;N&#39;</span><span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">sq</span> <span class="o">=</span> <span class="mi">0</span> <span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">w</span> <span class="o">==</span> <span class="sc">&#39;Y&#39;</span><span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">xb</span> <span class="o">=</span> <span class="mi">1</span> <span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">w</span> <span class="o">==</span> <span class="sc">&#39;N&#39;</span><span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">xb</span> <span class="o">=</span> <span class="mi">0</span> <span class="p">;</span>
    <span class="p">}</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="n">a</span><span class="p">;</span> <span class="n">i</span> <span class="o">++</span><span class="p">){</span>
        <span class="k">if</span><span class="p">(</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">pj</span> <span class="o">&gt;</span> <span class="mi">80</span> <span class="o">&amp;&amp;</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">lun</span><span class="o">&gt;=</span><span class="mi">1</span> <span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">money</span> <span class="o">+=</span> <span class="mi">8000</span> <span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">pj</span> <span class="o">&gt;</span> <span class="mi">85</span> <span class="o">&amp;&amp;</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">py</span> <span class="o">&gt;</span> <span class="mi">80</span><span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">money</span> <span class="o">+=</span> <span class="mi">4000</span> <span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">pj</span> <span class="o">&gt;</span> <span class="mi">90</span><span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">money</span> <span class="o">+=</span> <span class="mi">2000</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">pj</span> <span class="o">&gt;</span> <span class="mi">85</span> <span class="o">&amp;&amp;</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">xb</span> <span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">money</span> <span class="o">+=</span> <span class="mi">1000</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">py</span> <span class="o">&gt;</span> <span class="mi">80</span> <span class="o">&amp;&amp;</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">sq</span> <span class="p">)</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">money</span> <span class="o">+=</span> <span class="mi">850</span> <span class="p">;</span>
        <span class="n">sum</span> <span class="o">+=</span> <span class="n">st</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">money</span> <span class="p">;</span>
    <span class="p">}</span>
    <span class="n">sort</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">st</span><span class="p">,</span><span class="mi">1</span><span class="o">+</span><span class="n">st</span><span class="o">+</span><span class="n">a</span><span class="p">,</span><span class="n">cmp</span><span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\n</span><span class="s">%d</span><span class="se">\n</span><span class="s">%d&quot;</span><span class="p">,</span><span class="n">st</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">n</span><span class="p">,</span><span class="n">st</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">money</span><span class="p">,</span><span class="n">sum</span><span class="p">);</span>
    <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span> 
<span class="p">}</span>
</pre></div>
<p>三、</p>
<pre><code>珠心算测验
描述

珠心算是一种通过在脑中模拟算盘变化来完成快速运算的一种计算技术。珠心算训练， 既能够开发智力，又能够为日常生活带来很多便利，因而在很多学校得到普及。
某学校的珠心算老师采用一种快速考察珠心算加法能力的测验方法。他随机生成一个正整数集合，集合中的数各不相同，然后要求学生回答：其中有多少个数，恰好等于集合中另外两个（不同的）数之和？
最近老师出了一些测验题，请你帮忙求出答案。

格式

输入格式
输入共两行，第一行包含一个整数 n，表示测试题中给出的正整数个数。
第二行有 n 个正整数，每两个正整数之间用一个空格隔开，表示测试题中给出的正整数。

输出格式
输出共一行，包含一个整数，表示测验题答案。

样例1

样例输入1

4
1 2 3 4

样例输出1

2

限制
对于 100%的数据，3 ≤ n ≤ 100，测验题给出的正整数大小不超过 10,000。

提示
由 1+2=3，1+3=4，故满足测试要求的答案为 2。注意，加数和被加数必须是集合中的两个不同的数。

来源
NOIP2014 普及组</code></pre>
<p>瞎搞，暴力枚举也能过</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cstring&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;iostream&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;algorithm&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cmath&gt; </span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">;</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span><span class="kt">void</span> <span class="n">read</span><span class="p">(</span><span class="n">T</span> <span class="o">&amp;</span><span class="n">x</span><span class="p">){</span>
    <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">int</span> <span class="n">f</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">char</span> <span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;</span><span class="sc">&#39;0&#39;</span><span class="o">||</span><span class="n">ch</span><span class="o">&gt;</span><span class="sc">&#39;9&#39;</span><span class="p">){</span><span class="n">f</span><span class="o">|=</span><span class="p">(</span><span class="n">ch</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">);</span><span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();}</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;=</span><span class="sc">&#39;9&#39;</span><span class="o">&amp;&amp;</span><span class="n">ch</span><span class="o">&gt;=</span><span class="sc">&#39;0&#39;</span><span class="p">){</span><span class="n">x</span><span class="o">=</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">3</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">ch</span><span class="o">^</span><span class="mi">48</span><span class="p">);</span><span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();}</span>
    <span class="n">x</span><span class="o">=</span><span class="n">f</span><span class="o">?-</span><span class="nl">x</span><span class="p">:</span><span class="n">x</span><span class="p">;</span>
    <span class="k">return</span> <span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">q</span><span class="p">[</span><span class="mi">110</span><span class="p">],</span><span class="n">n</span><span class="p">;</span>

<span class="kt">bool</span> <span class="n">flg</span><span class="p">[</span><span class="mi">100010</span><span class="p">];</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">ans</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
    <span class="n">read</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">read</span><span class="p">(</span><span class="n">q</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
    <span class="n">sort</span><span class="p">(</span><span class="n">q</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">q</span><span class="o">+</span><span class="mi">1</span><span class="o">+</span><span class="n">n</span><span class="p">);</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="o">+</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
                <span class="k">if</span><span class="p">(</span><span class="n">q</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="n">q</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">==</span><span class="n">q</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&amp;&amp;</span><span class="n">q</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">!=</span><span class="n">q</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">&amp;&amp;</span><span class="n">q</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">!=</span><span class="n">q</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&amp;&amp;</span><span class="n">q</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">!=</span><span class="n">q</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
                    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">flg</span><span class="p">[</span><span class="n">q</span><span class="p">[</span><span class="n">k</span><span class="p">]])</span> <span class="n">ans</span><span class="o">++</span><span class="p">,</span><span class="n">flg</span><span class="p">[</span><span class="n">q</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="n">ans</span><span class="p">);</span>
    <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span>
<span class="p">}</span>
</pre></div>
<h3 id="toc-4">字符串处理</h3>
<p>一、</p>
<pre><code>乒乓球

描述
华华通过以下方式进行分析，首先将比赛每个球的胜负列成一张表，然后分别计算在11分制和21分制下，双方的比赛结果（截至记录末尾）。
比赛规则和实际比赛规则相同, 在11分制下比分为10:11时还要继续比赛，直到分数差距达到2分；同理21分制下比分为20:21的时候也还要继续比赛。
比如现在有这么一份记录，（其中W表示华华获得一分，L表示华华对手获得一分）：
WWWWWWWWWWWWWWWWWWWWWWLW
在11分制下，此时比赛的结果是华华第一局11比0获胜，第二局11比0获胜，正在进行第三局，当前比分1比1。而在21分制下，此时比赛结果是华华第一局21比0获胜，正在进行第二局，比分2比1。如果一局比赛刚开始，则此时比分为0比0。
你的程序就是要对于一系列比赛信息的输入（WL形式），输出正确的结果。

格式

输入格式

每个输入文件包含若干行字符串（每行至多20个字母），字符串有大写的W、L和E组成,也许中间有若干个空格。其中E表示比赛信息结束，程序应该忽略E之后的所有内容,E后面可能有干扰文字。

输出格式

输出由两部分组成，每部分有若干行，每一行对应一局比赛的比分（按比赛信息输入顺序）。其中第一部分是11分制下的结果，第二部分是21分制下的结果，两部分之间由一个空行分隔。

样例1

样例输入1
WWWWWWWWWWWWWWWWWWWW
WWLWE

样例输出1
11:0
11:0
1:1

21:0
2:1


限制
各个测试点1s

提示
十分简单，小心输入输出格式！^_^</code></pre>
<p>统计一下W和L的个数，分开处理就好了</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cstring&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;iostream&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;algorithm&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cmath&gt; </span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">;</span>
<span class="cp">#define xxx ch=getchar()</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span><span class="kt">void</span> <span class="n">read</span><span class="p">(</span><span class="n">T</span> <span class="o">&amp;</span><span class="n">x</span><span class="p">){</span>
    <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">int</span> <span class="n">f</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">char</span> <span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;</span><span class="sc">&#39;0&#39;</span><span class="o">||</span><span class="n">ch</span><span class="o">&gt;</span><span class="sc">&#39;9&#39;</span><span class="p">){</span><span class="n">f</span><span class="o">|=</span><span class="p">(</span><span class="n">ch</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">);</span><span class="n">xxx</span><span class="p">;}</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;=</span><span class="sc">&#39;9&#39;</span><span class="o">&amp;&amp;</span><span class="n">ch</span><span class="o">&lt;=</span><span class="sc">&#39;0&#39;</span><span class="p">){</span><span class="n">x</span><span class="o">=</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">3</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">ch</span><span class="o">^</span><span class="mi">48</span><span class="p">);</span><span class="n">xxx</span><span class="p">;}</span>
    <span class="n">x</span><span class="o">=</span><span class="n">f</span><span class="o">?-</span><span class="nl">x</span><span class="p">:</span><span class="n">x</span><span class="p">;</span>
    <span class="k">return</span> <span class="p">;</span>
<span class="p">}</span>

<span class="kt">char</span> <span class="n">c</span><span class="p">;</span>

<span class="kt">int</span> <span class="n">w1</span><span class="p">[</span><span class="mi">100001</span><span class="p">],</span><span class="n">w2</span><span class="p">[</span><span class="mi">10001</span><span class="p">],</span><span class="n">l1</span><span class="p">[</span><span class="mi">10001</span><span class="p">],</span><span class="n">l2</span><span class="p">[</span><span class="mi">10001</span><span class="p">];</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">a</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">int</span> <span class="n">b</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
    <span class="k">while</span><span class="p">((</span><span class="n">c</span><span class="o">=</span><span class="n">getchar</span><span class="p">())</span><span class="o">!=</span><span class="sc">&#39;E&#39;</span><span class="p">){</span>
        <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">==</span><span class="sc">&#39;W&#39;</span><span class="p">)</span> <span class="n">w1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">++</span><span class="p">,</span><span class="n">w2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">c</span><span class="o">==</span><span class="sc">&#39;L&#39;</span><span class="p">)</span> <span class="n">l1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">++</span><span class="p">,</span><span class="n">l2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">w1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">21</span><span class="o">||</span><span class="n">l1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">21</span><span class="p">)</span> <span class="k">if</span><span class="p">(</span><span class="n">w1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">-</span><span class="n">l1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">2</span><span class="o">||</span><span class="n">l1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">-</span><span class="n">w1</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">2</span><span class="p">)</span> <span class="n">a</span><span class="o">++</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span><span class="n">w2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">11</span><span class="o">||</span><span class="n">l2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">11</span><span class="p">)</span> <span class="k">if</span><span class="p">(</span><span class="n">w2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">-</span><span class="n">l2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">2</span><span class="o">||</span><span class="n">l2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">-</span><span class="n">w2</span><span class="p">[</span><span class="n">b</span><span class="p">]</span><span class="o">&gt;=</span><span class="mi">2</span><span class="p">)</span> <span class="n">b</span><span class="o">++</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">b</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d:%d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">w2</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">l2</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
    <span class="n">puts</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">);</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">a</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d:%d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">w1</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">l1</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
    <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>二、</p>
<pre><code>字符串还原

背景

小K是一位蔚蓝教主的崇拜者(Orz教主er)，有一天，他收到了一封匿名信，信告诉了小K由于他表现出色，得到了一次当面Orz教主的机会，但是要当面Orz教主可不那么容易，不是每个人都有资格Orz教主的。所以要破解下面一段密文才可以得到相关的信息，信中有提供加密的规则，但是小K觉得这个问题看似复杂，所以想请你帮忙。
描述

一个长度为n的由小写字母组成的字符串s_1~s_2~\cdots~s_n~s 
1
​   s 
2
​   ⋯ s 
n
​   按如下方式加密成3种形式：
1、将字符串翻转，即对于每一个1\le i\le n~1≤i≤n 来说，s_i~s 
i
​   与s_{n-i+1}~s 
n−i+1
​   对换。
2、将字符串中每个字母变为其之后第k个字母，定义z之后的字母为a，其中0≤k≤6且为未知数。
3、将字符串中每个字母变为其之前第k个字母，定义a之前的字母为z，k同2所述。
例如字符串abcd按上面3种方式加密后，在k=1k=1的情况下会依次变为：
1、dcba；
2、bcde；
3、zabc。
现给出信中按以上3种形式分别加密后的3个字符串（不一定按上述例子的顺序），要求还原原来的字符串，并输出告诉小K。

格式

输入格式

输入的第1行为一个整数n，表示这个字符串的长度。
下面3行每行1个长度为n的字符串，且保证符合题目要求。

输出格式

输出仅包括1行，为还原后的字符串。

样例1

样例输入1
4
zabc
dcba
bcde

样例输出1
abcd


限制
对于10%的数据，输入给出加密字符串的顺序同题目中1、2、3的顺序。
对于20%的数据，n≤5； 
对于40%的数据，n≤10； 
对于60%的数据，n≤255；
对于100%的数据，n≤10000。

时限1s</code></pre>
<p>三次判断，每次判断其中的一个是否应该被翻转，一共三种情况，然后反向输出那个应该被翻转的就是原串了</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;cstring&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;algorithm&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;vector&gt;</span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>

<span class="k">const</span> <span class="kt">int</span> <span class="n">maxn</span> <span class="o">=</span> <span class="mf">1e5</span> <span class="o">+</span> <span class="mi">7</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">a</span><span class="p">[</span><span class="n">maxn</span><span class="p">],</span> <span class="n">b</span><span class="p">[</span><span class="n">maxn</span><span class="p">],</span> <span class="n">c</span><span class="p">[</span><span class="n">maxn</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">bool</span> <span class="nf">chk</span><span class="p">(</span> <span class="kt">char</span><span class="o">*</span> <span class="n">a</span><span class="p">,</span> <span class="kt">char</span><span class="o">*</span> <span class="n">b</span><span class="p">,</span> <span class="kt">char</span><span class="o">*</span> <span class="n">c</span><span class="p">){</span>
    <span class="k">for</span> <span class="p">(</span> <span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span> <span class="p">){</span>
        <span class="kt">int</span> <span class="n">x</span><span class="o">=</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-</span><span class="sc">&#39;a&#39;</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">y</span><span class="o">=</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-</span><span class="sc">&#39;a&#39;</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">z</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="sc">&#39;a&#39;</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span> <span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">z</span><span class="p">)</span><span class="o">%</span><span class="mi">26</span> <span class="o">!=</span> <span class="mi">0</span> <span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(){</span>
    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">n</span> <span class="p">);</span>
    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%s&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%s&quot;</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%s&quot;</span><span class="p">,</span> <span class="n">c</span><span class="p">);</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">chk</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">)</span> <span class="p">){</span>
        <span class="k">for</span> <span class="p">(</span> <span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">&gt;=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">--</span> <span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">);</span>
    <span class="p">}</span><span class="k">else</span> <span class="k">if</span><span class="p">(</span> <span class="n">chk</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">c</span><span class="p">)</span> <span class="p">){</span>
        <span class="k">for</span> <span class="p">(</span> <span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">&gt;=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">--</span> <span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c&quot;</span><span class="p">,</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">);</span>
    <span class="p">}</span><span class="k">else</span> <span class="p">{</span>
        <span class="k">for</span> <span class="p">(</span> <span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">&gt;=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">--</span> <span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c&quot;</span><span class="p">,</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">);</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>三、</p>
<pre><code>ISBN号码

描述
每一本正式出版的图书都有一个ISBN号码与之对应，ISBN码包括9位数字、1位识别码和3位分隔符，其规定格式如“x-xxx-xxxxx-x”，其中符号“-”就是分隔符（键盘上的减号），最后一位是识别码，例如0-670-82162-4就是一个标准的ISBN码。ISBN码的首位数字表示书籍的出版语言，例如0代表英语；第一个分隔符“-”之后的三位数字代表出版社，例如670代表维京出版社；第二个分隔符后的五位数字代表该书在该出版社的编号；最后一位为识别码。
识别码的计算方法如下：
首位数字乘以1加上次位数字乘以2……以此类推，用所得的结果mod 11，所得的余数即为识别码，如果余数为10，则识别码为大写字母X。例如ISBN号码0-670-82162-4中的识别码4是这样得到的：对067082162这9个数字，从左至右，分别乘以1，2，...,9,再求和，即0×1+6×2+……+2×9=158，然后取158 mod 11的结果4作为识别码。
你的任务是编写程序判断输入的ISBN号码中识别码是否正确，如果正确，则仅输出“Right”；如果错误，则输出你认为是正确的ISBN号码。

格式

输入格式

输入只有一行，是一个字符序列，表示一本书的ISBN号码（保证输入符合ISBN号码的格式要求）。

输出格式

输出共一行，假如输入的ISBN号码的识别码正确，那么输出“Right”，否则，按照规定的格式，输出正确的ISBN号码（包括分隔符“-”）。

样例1

样例输入1
0-670-82162-4

样例输出1
Right

样例2

样例输入2
0-670-82162-0

样例输出2
0-670-82162-4

限制
各个测试点1s

来源
NOIP2008复赛</code></pre>
<p>水题，多判断几次就好了</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cstring&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;iostream&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;algorithm&gt;</span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">;</span>
<span class="kt">char</span> <span class="n">si</span><span class="p">[</span><span class="mi">15</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">s</span><span class="p">[</span><span class="mi">15</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">a</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%s&quot;</span><span class="p">,</span><span class="n">si</span><span class="p">);</span>
    <span class="kt">int</span> <span class="n">len</span> <span class="o">=</span> <span class="n">strlen</span><span class="p">(</span><span class="n">si</span><span class="p">);</span><span class="c1">//x-xxx-xxxxx-</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">len</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
        <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">si</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-</span><span class="sc">&#39;0&#39;</span><span class="p">;</span>
    <span class="n">a</span><span class="o">=</span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="mi">1</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="mi">3</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">6</span><span class="p">]</span><span class="o">*</span><span class="mi">5</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">7</span><span class="p">]</span><span class="o">*</span><span class="mi">6</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">8</span><span class="p">]</span><span class="o">*</span><span class="mi">7</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span><span class="o">*</span><span class="mi">8</span><span class="o">+</span><span class="n">s</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span><span class="o">*</span><span class="mi">9</span><span class="p">;</span>

    <span class="n">a</span><span class="o">%=</span><span class="mi">11</span><span class="p">;</span>    
    <span class="kt">bool</span> <span class="n">qwq</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>

    <span class="k">if</span><span class="p">(</span><span class="n">a</span><span class="o">==</span><span class="mi">10</span><span class="o">&amp;&amp;</span><span class="n">si</span><span class="p">[</span><span class="n">len</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;X&#39;</span><span class="p">){</span>
        <span class="n">qwq</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="n">a</span><span class="o">==</span><span class="mi">10</span> <span class="o">&amp;&amp;</span> <span class="n">si</span><span class="p">[</span><span class="n">len</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">!=</span><span class="sc">&#39;X&#39;</span><span class="p">){</span>
        <span class="n">si</span><span class="p">[</span><span class="n">len</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="sc">&#39;X&#39;</span><span class="p">;</span>
        <span class="n">puts</span><span class="p">(</span><span class="n">si</span><span class="p">);</span>
        <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span>
    <span class="p">}</span>

    <span class="k">if</span><span class="p">(</span><span class="n">a</span><span class="o">==</span><span class="n">s</span><span class="p">[</span><span class="n">len</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="n">qwq</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="k">if</span><span class="p">(</span><span class="n">qwq</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Right&quot;</span><span class="p">);</span>
    <span class="k">else</span> <span class="p">{</span>
        <span class="n">si</span><span class="p">[</span><span class="n">len</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="o">+</span><span class="sc">&#39;0&#39;</span> <span class="p">;</span>
        <span class="n">puts</span><span class="p">(</span><span class="n">si</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span>
<span class="p">}</span>
</pre></div>
<h3 id="toc-5">枚举</h3>
<p>一、</p>
<pre><code>回文数

描述
若一个数（首位不为零）从左向右读与从右向左读都一样，我们就将其称之为回文数。
例如：给定一个10进制数56，将56加65（即把56从右向左读），得到121是一个回文数。
又如：对于10进制数87：
STEP1：87+78 = 165 STEP2：165+561 = 726
STEP3：726+627 = 1353 STEP4：1353+3531 = 4884
在这里的一步是指进行了一次N进制的加法，上例最少用了4步得到回文数4884。
写一个程序，给定一个N（2&lt;=N&lt;=10或N=16）进制数M，其中16进制数字为0-9与A-F，求最少经过几步可以得到回文数。如果在30步以内（包含30步）不可能得到回文数，则输出“Impossible!

格式

输入格式

共两行
第一行为进制数N（2&lt;=N&lt;=10或N=16）
第二行为N进制数M（0&lt;=M&lt;=maxlongint）
输出格式

共一行
第一行为“STEP=”加上经过的步数或“Impossible!”

样例1
样例输入1
9
87

样例输出1
STEP=6

限制
各个测试点1s

来源
NOIP1999提高组第2题</code></pre>
<p>高精度模拟，好麻烦...</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;iostream&gt;  </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cstring&gt;  </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;  </span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>  
<span class="n">string</span> <span class="n">x</span><span class="p">;</span>  
<span class="kt">int</span> <span class="n">jz</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">a</span><span class="p">[</span><span class="mi">10001</span><span class="p">],</span><span class="n">s</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>  
<span class="kt">int</span> <span class="nf">pdhw</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span>  
<span class="p">{</span>  
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">n</span><span class="o">/</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>  
        <span class="k">if</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">!=</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span>  
            <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>  
    <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>  
<span class="p">}</span>  
<span class="kt">int</span> <span class="nf">jf</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span>  
<span class="p">{</span>  
    <span class="kt">int</span> <span class="n">c</span><span class="p">[</span><span class="mi">10001</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">},</span><span class="n">s</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>  
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>  
    <span class="p">{</span>  
        <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>  
        <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">+=</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">/</span><span class="n">jz</span><span class="p">;</span>  
        <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">%=</span><span class="n">jz</span><span class="p">;</span>  
    <span class="p">}</span>  
    <span class="k">if</span> <span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">!=</span><span class="mi">0</span><span class="p">)</span>  
        <span class="n">n</span><span class="o">++</span><span class="p">;</span>  
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">&gt;=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">--</span><span class="p">)</span>  
    <span class="p">{</span>  
        <span class="n">a</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">=</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>  
        <span class="n">s</span><span class="o">++</span><span class="p">;</span>  
    <span class="p">}</span>  
    <span class="k">return</span> <span class="n">n</span><span class="p">;</span>  
<span class="p">}</span>  
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>  
<span class="p">{</span>  
    <span class="n">cin</span><span class="o">&gt;&gt;</span><span class="n">jz</span><span class="o">&gt;&gt;</span><span class="n">x</span><span class="p">;</span>  
    <span class="n">n</span><span class="o">=</span><span class="n">x</span><span class="p">.</span><span class="n">size</span><span class="p">();</span>  
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>  
    <span class="p">{</span>  
        <span class="k">if</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">&lt;</span><span class="mi">65</span><span class="p">)</span>  
            <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="sc">&#39;0&#39;</span><span class="p">;</span>  
        <span class="k">else</span>  
            <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="mi">55</span><span class="p">;</span>  
    <span class="p">}</span>  
    <span class="k">while</span><span class="p">(</span><span class="n">s</span><span class="o">&lt;=</span><span class="mi">30</span><span class="p">)</span>  
    <span class="p">{</span>  
        <span class="k">if</span><span class="p">(</span><span class="n">pdhw</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">==</span><span class="mi">1</span><span class="p">)</span>  
        <span class="p">{</span>  
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;STEP=&quot;</span><span class="o">&lt;&lt;</span><span class="n">s</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>  
            <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>  
        <span class="p">}</span>  
        <span class="n">s</span><span class="o">++</span><span class="p">;</span>  
        <span class="n">n</span><span class="o">=</span><span class="n">jf</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>  
    <span class="p">}</span>  
    <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;Impossible!&quot;</span><span class="p">;</span>  
<span class="p">}</span>
</pre></div>
<p>二、</p>
<pre><code>巧妙填数

描述

将1,2,\cdots,91,2,⋯,9共99个数分成三组，分别组成三个三位数，且使这三个三位数构成1:2:31:2:3的比例。
试求出所有满足条件的三个三位数。
例如：三个三位数192,384,576192,384,576满足以上条件。

格式

输入格式
无输入。

输出格式
需要输出全部结果。每行输出3个数 用空格隔开。按照字典序的顺序输出。

来源
NOIP 1998 普及组 第一题</code></pre>
<p>手推</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cstring&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;iostream&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;algorithm&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cmath&gt;</span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">;</span>
<span class="cp">#define xxx ch=getchar()</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span><span class="kt">void</span> <span class="n">read</span><span class="p">(</span><span class="n">T</span> <span class="o">&amp;</span><span class="n">x</span><span class="p">){</span>
    <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">int</span> <span class="n">f</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">char</span> <span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;</span><span class="sc">&#39;0&#39;</span><span class="o">||</span><span class="n">ch</span><span class="o">&gt;</span><span class="sc">&#39;9&#39;</span><span class="p">){</span><span class="n">f</span><span class="o">|=</span><span class="p">(</span><span class="n">ch</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">);</span><span class="n">xxx</span><span class="p">;}</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;=</span><span class="sc">&#39;9&#39;</span><span class="o">&amp;&amp;</span><span class="n">ch</span><span class="o">&gt;=</span><span class="sc">&#39;0&#39;</span><span class="p">){</span><span class="n">x</span><span class="o">=</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">3</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">ch</span><span class="o">^</span><span class="mi">48</span><span class="p">);</span><span class="n">xxx</span><span class="p">;}</span>
    <span class="n">x</span><span class="o">=</span><span class="n">f</span><span class="o">?-</span><span class="nl">x</span><span class="p">:</span><span class="n">x</span><span class="p">;</span>
    <span class="k">return</span> <span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;192 384 576</span><span class="se">\n</span><span class="s">219 438 657</span><span class="se">\n</span><span class="s">273 546 819</span><span class="se">\n</span><span class="s">327 654 981&quot;</span><span class="p">);</span>
    <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>三、</p>
<pre><code>数与连分数

背景
...

...:“这个简单...我们还是去刚才的海边呗...”
...:"其实今晚...我是有一定要完成的事情的..." .,
威尼斯真的是一个美丽的城市...很小的时候我就听说这个地方..
这一天..从贝鲁特归来的商队..除了布匹和香辛料...还带来的东方的数字....
也有人曾经讨论过它们的历史...
只是很长时间这些都不被那些数学家们所重视..
人们怀着敬畏的心情..小心的审视着这些新奇的东西...
而它们..给生活在这片土地上的人们所带来的..是很大的帮助..
...
描述

写一个程序...可以实现在连分数和分数之间的互相转换...

样例1

样例输入1
[2;3,7]
51/22

样例输出1
51/22
[2;3,7]


限制
出题人不透露

提示
多组测试数据:
每一个测试点有多组数据...数据的组数不超过100组。
约分:
计算结果最后是要约分的...但是..在分数转向连分数的时候..
我们不保证输入的数据是约分.....
连分数的输入格式:
连分数的输入格式是按照wiki里写的...
第一个位置的分号应该是为了避免可能的歧义~..
English:
我们校内的时候又同学抱怨英文看不懂...可以访问这个页...蛮好用的...
或者在wiki左侧的语言栏里最下面找中文切换一下就行了...
Range:
数字的规模都很小...
也就是它们都不会超过longint范围里....
包括中间的数据...
连分数的项数也不会超过100项..
See also:
连分数的其它知识..可以阅读....至于这个.....</code></pre>
<p>真丶大暴力，注意约分的情况</p>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;bits/stdc++.h&gt;</span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">;</span>

<span class="kt">int</span> <span class="nf">gcd</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span><span class="kt">int</span> <span class="n">y</span><span class="p">){</span><span class="k">return</span> <span class="n">y</span><span class="o">==</span><span class="mi">0</span><span class="o">?</span><span class="nl">x</span><span class="p">:</span><span class="n">gcd</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="o">%</span><span class="n">y</span><span class="p">);}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="n">string</span> <span class="n">s</span><span class="p">;</span><span class="kt">char</span> <span class="n">c</span><span class="p">;</span>
    <span class="k">while</span><span class="p">(</span><span class="n">getline</span><span class="p">(</span><span class="n">cin</span><span class="p">,</span><span class="n">s</span><span class="p">)){</span>
        <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">isdigit</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">])){</span>
            <span class="kt">int</span> <span class="n">d</span><span class="p">;</span><span class="n">stack</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="n">ans</span><span class="p">;</span>
            <span class="n">stringstream</span> <span class="n">ss</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
            <span class="n">ss</span><span class="o">&gt;&gt;</span><span class="n">c</span><span class="p">;</span>
            <span class="k">while</span><span class="p">(</span><span class="n">ss</span><span class="o">&gt;&gt;</span><span class="n">d</span><span class="o">&gt;&gt;</span><span class="n">c</span><span class="p">)</span> <span class="n">ans</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">d</span><span class="p">);</span>
            <span class="kt">int</span> <span class="n">fz</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="n">fm</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
            <span class="k">while</span><span class="p">(</span><span class="o">!</span><span class="n">ans</span><span class="p">.</span><span class="n">empty</span><span class="p">()){</span>
                <span class="kt">int</span> <span class="n">x</span><span class="o">=</span><span class="n">ans</span><span class="p">.</span><span class="n">top</span><span class="p">();</span>
                <span class="n">ans</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
                <span class="n">swap</span><span class="p">(</span><span class="n">fz</span><span class="p">,</span><span class="n">fm</span><span class="p">);</span>
                <span class="n">fz</span><span class="o">+=</span><span class="n">x</span><span class="o">*</span><span class="n">fm</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="kt">int</span> <span class="n">gg</span><span class="o">=</span><span class="n">gcd</span><span class="p">(</span><span class="n">fz</span><span class="p">,</span><span class="n">fm</span><span class="p">);</span>
            <span class="n">fz</span><span class="o">/=</span><span class="n">gg</span><span class="p">;</span><span class="n">fm</span><span class="o">/=</span><span class="n">gg</span><span class="p">;</span>
            <span class="k">if</span><span class="p">(</span><span class="n">fm</span><span class="o">==</span><span class="mi">1</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">fz</span><span class="p">);</span>
            <span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d/%d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">fz</span><span class="p">,</span><span class="n">fm</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="k">else</span> <span class="p">{</span>
            <span class="kt">int</span> <span class="n">fz</span><span class="p">,</span><span class="n">fm</span><span class="p">;</span>
            <span class="n">queue</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="n">ans</span><span class="p">;</span>
            <span class="n">stringstream</span> <span class="n">ss</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
            <span class="n">ss</span><span class="o">&gt;&gt;</span><span class="n">fz</span><span class="o">&gt;&gt;</span><span class="n">c</span><span class="o">&gt;&gt;</span><span class="n">fm</span><span class="p">;</span>
            <span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">){</span>
                <span class="kt">int</span> <span class="n">t</span><span class="o">=</span><span class="n">fz</span><span class="o">/</span><span class="n">fm</span><span class="p">;</span>
                <span class="n">ans</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">t</span><span class="p">);</span>
                <span class="n">fz</span><span class="o">=</span><span class="n">fz</span><span class="o">-</span><span class="n">t</span><span class="o">*</span><span class="n">fm</span><span class="p">;</span>
                <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">fz</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
                <span class="n">swap</span><span class="p">(</span><span class="n">fz</span><span class="p">,</span><span class="n">fm</span><span class="p">);</span>
            <span class="p">}</span>
            <span class="k">if</span><span class="p">(</span><span class="n">ans</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o">==</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;[%d]&quot;</span><span class="p">,</span><span class="n">ans</span><span class="p">.</span><span class="n">front</span><span class="p">());</span><span class="k">continue</span><span class="p">;}</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&quot;[%d;&quot;</span><span class="p">,</span><span class="n">ans</span><span class="p">.</span><span class="n">front</span><span class="p">());</span>
            <span class="n">ans</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
            <span class="k">while</span><span class="p">(</span><span class="n">ans</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o">!=</span><span class="mi">1</span><span class="p">){</span>
                <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d,&quot;</span><span class="p">,</span><span class="n">ans</span><span class="p">.</span><span class="n">front</span><span class="p">());</span>
                <span class="n">ans</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
            <span class="p">}</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d]</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">ans</span><span class="p">.</span><span class="n">front</span><span class="p">());</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>四、</p>
<pre><code>数独验证
背景

XX学校风靡一款智力游戏，也就是数独（九宫格），先给你一个数独，并需要你验证是否符合规则。

描述

具体规则如下:
每一行都用到1,2,3,4,5,6,7,8,9，位置不限，
每一列都用到1,2,3,4,5,6,7,8,9，位置不限，
每3×3的格子（共九个这样的格子）都用到1,2,3,4,5,6,7,8,9，位置不限，
游戏的过程就是用1,2,3,4,5,6,7,8,9填充空白，并要求满足每行、每列、每个九宫格都用到1,2,3,4,5,6,7,8,9。
如下是一个正确的数独:
5 8 1 4 9 3 7 6 2
9 6 3 7 1 2 5 8 4
2 7 4 8 6 5 9 3 1
1 2 9 5 4 6 3 7 8
4 3 6 1 8 7 2 9 5
7 5 8 3 2 9 1 4 6
8 9 2 6 7 1 4 5 3
6 1 5 9 3 4 8 2 7
3 4 7 2 5 8 6 1 9

格式

输入格式
输入n个数独，你来验证它是否违反规则.
第一行为数独个数，第二行开始为第一个数独，之后为第二个，至第n个.
注意！每个数独之间有一个回车隔开!

输出格式
若正确则输出”Right”若不正确则输出”Wrong” 输出一个换一行

样例1

样例输入1
2
5 8 1 4 9 3 7 6 2
9 6 3 7 1 2 5 8 4
2 7 4 8 6 5 9 3 1
1 2 9 5 4 6 3 7 8
4 3 6 1 8 7 2 9 5
7 5 8 3 2 9 1 4 6
8 9 2 6 7 1 4 5 3
6 1 5 9 3 4 8 2 7
3 4 7 2 5 8 6 1 9

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8

样例输出1
Right
Wrong

限制
各个测试点1s

提示
1&lt;=n&lt;=20 （输入的数独个数）
不论输入的数独是错误的还是正确的,数据都保证每个数在1-9之间,即只会出现因为有相同的数而导致违反规则,而不会因为数字超出了1-9的范围而违反规则.</code></pre>
<div class="highlight"><pre><span></span><span class="cp">#include</span><span class="cpf">&lt;cstdio&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cstring&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;iostream&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;algorithm&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;cmath&gt; </span><span class="cp"></span>
<span class="cp">#include</span><span class="cpf">&lt;set&gt;</span><span class="cp"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">;</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span><span class="kt">void</span> <span class="n">read</span><span class="p">(</span><span class="n">T</span> <span class="o">&amp;</span><span class="n">x</span><span class="p">){</span>
    <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">int</span> <span class="n">f</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">char</span> <span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;</span><span class="sc">&#39;0&#39;</span><span class="o">||</span><span class="n">ch</span><span class="o">&gt;</span><span class="sc">&#39;9&#39;</span><span class="p">){</span><span class="n">f</span><span class="o">|=</span><span class="p">(</span><span class="n">ch</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">);</span><span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();}</span>
    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="o">&lt;=</span><span class="sc">&#39;9&#39;</span><span class="o">&amp;&amp;</span><span class="n">ch</span><span class="o">&gt;=</span><span class="sc">&#39;0&#39;</span><span class="p">){</span><span class="n">x</span><span class="o">=</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">x</span><span class="o">&lt;&lt;</span><span class="mi">3</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">ch</span><span class="o">^</span><span class="mi">48</span><span class="p">);</span><span class="n">ch</span><span class="o">=</span><span class="n">getchar</span><span class="p">();}</span>
    <span class="n">x</span><span class="o">=</span><span class="n">f</span><span class="o">?-</span><span class="nl">x</span><span class="p">:</span><span class="n">x</span><span class="p">;</span>
    <span class="k">return</span> <span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">w</span><span class="p">[</span><span class="mi">10</span><span class="p">][</span><span class="mi">10</span><span class="p">];</span>

<span class="kt">bool</span> <span class="nf">work</span><span class="p">(){</span>
    <span class="n">set</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="n">s</span><span class="p">;</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="n">s</span><span class="p">.</span><span class="n">clear</span><span class="p">();</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">s</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">w</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
        <span class="k">if</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o">!=</span><span class="mi">9</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
        <span class="n">s</span><span class="p">.</span><span class="n">clear</span><span class="p">();</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">s</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">w</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]);</span>
        <span class="k">if</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o">!=</span><span class="mi">9</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">i</span><span class="o">+=</span><span class="mi">3</span><span class="p">)</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">j</span><span class="o">+=</span><span class="mi">3</span><span class="p">){</span>
            <span class="n">s</span><span class="p">.</span><span class="n">clear</span><span class="p">();</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;</span><span class="mi">3</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
                <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">m</span><span class="o">&lt;</span><span class="mi">3</span><span class="p">;</span><span class="n">m</span><span class="o">++</span><span class="p">)</span>
                    <span class="n">s</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">w</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="n">m</span><span class="p">]);</span>
            <span class="k">if</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o">!=</span><span class="mi">9</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">T</span><span class="p">;</span>
    <span class="n">read</span><span class="p">(</span><span class="n">T</span><span class="p">)</span> <span class="p">;</span>
    <span class="k">while</span><span class="p">(</span><span class="n">T</span><span class="o">--</span><span class="p">){</span>
        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">9</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
                <span class="n">read</span><span class="p">(</span><span class="n">w</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
        <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">work</span><span class="p">())</span> <span class="n">puts</span><span class="p">(</span><span class="s">&quot;Wrong&quot;</span><span class="p">);</span>
        <span class="k">else</span> <span class="n">puts</span><span class="p">(</span><span class="s">&quot;Right&quot;</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="mi">0</span> <span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>By:Wahacer</p>
<p>2017.10.17</p>
<p>22:20</p>


        </div>
  </div>
</div>
<!-- Footer
    ================================================== -->
<footer class="footer">
  <div class="container">
         Copyright (c) 2017 Powered By <a href="https://gitee.com/uncle-lu/oub">OUB</a>
         <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/3.0/cn/88x31.png" /></a><br />本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/">知识共享署名-非商业性使用-相同方式共享 3.0 中国大陆许可协议</a>进行许可。
  </div>
</footer>
<script>
    $('h1').each(function() {
        $(this).wrap('<section id="' + this.id + '"/>');
    });

    $('h1').wrap('<div class="page-header" />');
    $('h1').wrap('<div class="well well-small" />');

    $(document).ready(function() {
        var items = [];
        $('h1').each(function() {
            items.push('<li><a href="#' + this.id + '"><i class="fa fa-chevron-right pull-right"></i> ' + $(this).text() + '</a></li>');
        });  // close each()

    $('#sidebar_list').append( items.join('') );

    $('table').each(function() {
        $(this).addClass('table table-striped table-condensed table-hover');
    });

    $('.done0').each(function() {
        $(this).html('<div class="alert alert-info"><i class="fa fa-check-square-o"></i>'+$(this).html()+'</div></li>');
    });

    $('.done4').each(function() {
        $(this).html('<div class="alert alert-success"><i class="fa fa-square-o"></i>'+$(this).html()+'</div></li>');
    });
   
    $('pre').each(function() {
        $(this).html('<code>'+$(this).html()+'</code>');
    });
    hljs.initHighlightingOnLoad();
});
</script>
</body>
</html>